--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  1A_housing_merge.log
  log type:  text
 opened on:  13 Apr 2018, 11:49:24

. cd "$dataDir" ;
C:\REPLICATION\data_working

. set more off ;

. ***************************************************************************;
. * FOR SOME REASON FAMILY HOUSING SUBSIDY IS NOT INCLUDED IN THE IPUMS CPS. ;
. ***************************************************************************;
. ***************************************************************************;
. * START WITH THE IPUMS CPS IDENTIFIERS ;
. ***************************************************************************;
. * READ IN RAW IPUMS WITH IDENTIFIERS ;
. local cps "cps_00007";

. capture erase `cps'.do ;

. capture erase `cps'.dat ;

. capture erase `cps'.dat.gz ;

. local from "$rawDir\\`cps'.dat.gz" ;

. local to "$dataDir\\`cps'.dat.gz"  ;

. copy `from' `to' , replace;

. shell 7za e `cps'.dat.gz ;

. local from "$rawDir\\`cps'.do" ;

. local to "$dataDir\\`cps'.do"  ;

. copy `from' `to' , replace;

. quietly do `cps'.do ;

. summ ;

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        year |  6,335,348    1998.555    10.59309       1980       2015
      serial |  6,335,348    43199.64    25937.22          1      99986
     hwtsupp |  6,335,348    1554.461    1028.542          0   28654.31
    asecflag |  6,335,348           1           0          1          1
       hflag |    199,556    .3013741     .458856          0          1
-------------+---------------------------------------------------------
        hseq |  6,335,348    43712.07    26161.04          1      99986
       nfams |  6,335,348    1.118989    .4453624          0         15
       month |  6,335,348           3           0          3          3
      pernum |  6,335,348    2.272117    1.391967          1         26
      wtsupp |  6,335,348    1576.438    1062.923          0   44423.83
-------------+---------------------------------------------------------
      lineno |  6,335,348    2.320558    1.463921          0         39
      relate |  6,335,348    269.8157    252.3589        101       1260
         age |  6,335,348    34.18893    22.04998          0         99
         sex |  6,335,348    1.516337    .4997331          1          2
        race |  6,335,348    144.9994    136.2038        100        830
-------------+---------------------------------------------------------
       asian |    601,214    95.49322    15.16248         10         99
       marst |  6,335,348    3.658421    2.349389          1          6
       ftype |  6,335,348    1.314301     .843926          1          5
     famkind |  6,335,348    1.542785     .829383          1          3
      famrel |  5,011,506        1.84    1.138058          0          4

. save cps_ipums_id_raw, replace ;
file cps_ipums_id_raw.dta saved

. clear ;

. ***************************************************************************;
. * PREP RAW CPS FOR MERGE ;
. ***************************************************************************;
. local cps "cps_extract_092816_stata13";

. capture erase `cps'.dta ;

. capture erase `cps'.zip ;

. local from "$rawDir\\`cps'.zip" ;

. local to "$dataDir\\`cps'.zip"  ;

. copy `from' `to' , replace;

. shell 7za e `cps'.zip ;

. use cps_extract_092816_stata13 ;

. keep year h_seq p_pos f_houssub f_mv_sl;

. drop if year == 1988 & p_pos <= 40 ;
(155,906 observations deleted)

. gen pernum = p_pos ;

. replace pernum = pernum-40 if pernum>40 ;
(5,011,506 real changes made)

. rename h_seq hseq ;

. drop p_pos ;

. sort year hseq pernum ;

. save rawcpsmerge, replace ;
(note: file rawcpsmerge.dta not found)
file rawcpsmerge.dta saved

. clear ;

. use cps_ipums_id_raw ;

. keep if year >= 1985 ;
(849,351 observations deleted)

. keep year hseq pernum serial ;

. sort year hseq pernum ;

. merge 1:1 year hseq pernum using rawcpsmerge ;
(note: variable pernum was byte, now float to accommodate using data's values)

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                         5,485,997  (_merge==3)
    -----------------------------------------

. rm rawcpsmerge.dta ;

. keep year serial pernum f_houssub f_mv_sl ;

. sort year serial pernum ;

. duplicates report year serial pernum ;

Duplicates in terms of year serial pernum

--------------------------------------
   copies | observations       surplus
----------+---------------------------
        1 |      5485997             0
--------------------------------------

. save housing_sub_cps, replace ;
file housing_sub_cps.dta saved

. exit ;

end of do-file


